python 您所在的位置:网站首页 Python中color[-1][2] python

python

2024-03-19 15:32| 来源: 网络整理| 查看: 265

1、定义 此模块包括用于颜色规格转换的函数和类,以及用于将数字映射为一维颜色数组(称为颜色映射)中的颜色的函数和类。 matplotlib识别以下格式以指定颜色: (1)以闭合间隔表示的浮点值的RGB或RGBA(红、绿、蓝、α)元组 [0, 1] (例如, (0.1, 0.2, 0.5) 或 (0.1, 0.2, 0.5, 0.3) ; (2)十六进制rgb或rgb a字符串(例如, ‘#0f0f0f’ 或 ‘#0f0f0f80’ ;不区分大小写); (3)一种简写的十六进制RGB或RGBA字符串,相当于通过复制每个字符获得的十六进制RGB或RGBA字符串(例如。, ‘#abc’ ,相当于 ‘#aabbcc’ 或 ‘#abcd’ ,相当于 ‘#aabbccdd’ ;不区分大小写) (4)浮点值的字符串表示形式 [0, 1] 包括灰级(例如, ‘0.5’ ; (5)其中一个角色 {{‘b’, ‘g’, ‘r’, ‘c’, ‘m’, ‘y’, ‘k’, ‘w’}} ,是蓝色、绿色、红色、青色、品红、黄色、黑色和白色的简写符号。注意颜色 ‘g’, ‘c’, ‘m’, ‘y’ 与X11/CSS4颜色不一致。他们选择了特殊的色调,以便在典型背景下更好地看到彩色线条。 (6)X11/CSS4颜色名称(不区分大小写); (7)名字来自 xkcd color survey 前缀 ‘xkcd:’ (例如, ‘xkcd:sky blue’ ;不区分大小写); (8)“T10”类别调色板中的一种Tableau颜色(默认颜色循环): {{‘tab:blue’, ‘tab:orange’, ‘tab:green’, ‘tab:red’, ‘tab:purple’, ‘tab:brown’, ‘tab:pink’, ‘tab:gray’, ‘tab:olive’, ‘tab:cyan’}} (不区分大小写); (9)“CN”颜色规范,即“C”后跟一个数字,这是默认属性周期的索引 (rcParams[“axes.prop_cycle”] (default: cycler(‘color’, [’#1f77b4’, ‘#ff7f0e’, ‘#2ca02c’, ‘#d62728’, ‘#9467bd’, ‘#8c564b’, ‘#e377c2’, ‘#7f7f7f’, ‘#bcbd22’, ‘#17becf’])) );索引将在渲染时发生,如果循环不包括颜色,则默认为黑色。

几个类如下: (1)BoundaryNorm:基于离散区间生成颜色映射索引 主要参数:boundaries—单调递增的边界序列 ncolors--------要使用的颜色映射中的颜色数

例子: 自定义颜色条:

data=np.random.randint(-100,100,(200,100)) #创建画布 fig,ax=plt.subplots(figsize=(6,6)) #映射 cmap=mpl.cm.cool norm=mpl.colors.Normalize(vmin=0,vmax=100) ca=ax.pcolormesh(data,cmap=cmap,norm=norm) fig.colorbar(ca,ax=ax)

结果如下: 在这里插入图片描述 如果把ax=ax,换成cax=ax.会得到如下结果: 在这里插入图片描述 先在这儿做一个记录,具体含义以后等弄明白了再说 离散间隔:

fig, ax = plt.subplots(figsize=(6, 1)) fig.subplots_adjust(bottom=0.5) cmap = mpl.cm.cool bounds = [-1, 2, 5, 7, 12, 15] norm = mpl.colors.BoundaryNorm(bounds, cmap.N, extend='both') #extend表示两端都有箭头 #BoundaryNorm表示基于离散区间取间隔值 fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=cmap), cax=ax, orientation='horizontal', label="Discrete intervals with extend='both' keyword")

结果如下: 在这里插入图片描述

fig, ax = plt.subplots(1, 2, figsize=(4, 4)) # fig.subplots_adjust(right=0.5) data = np.random.random((10, 10)) * 5 + 5 cmap = mpl.cm.cool norm = mpl.colors.Normalize(vmin=5, vmax=10) cs = ax[0].pcolormesh(data, cmap=cmap, norm=norm) cs = ax[1].pcolormesh(data, cmap=cmap, norm=norm) fig.colorbar(cs, ax=ax, orientation='vertical', label='Some Units') plt.show()

在这里插入图片描述

(2)Colormap



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有